package top.superflow.flow.validate

import top.superflow.exception.RequestUnsupportedException
import top.superflow.flow.config.process.ProcessConfig
import top.superflow.flow.config.{Config, FlowConfig}
import top.superflow.flow.load.GlobalFlowConfiguration
import top.superflow.inner.micro.flow.rule.RuleConfig

import scala.collection.mutable.Map

class DependencyValidationManager {

  private var flowConfiguration : GlobalFlowConfiguration = _
  
  def isValid(flowConfiguration : GlobalFlowConfiguration) : Boolean = {
    this.flowConfiguration = flowConfiguration
    
    validate(flowConfiguration)
    true
  }
  
  private def validate(flowConfigurationAllInOne : GlobalFlowConfiguration){
    validate(flowConfigurationAllInOne.getFlows)
  }
  
  private def validate[T <: Config](elements : Map[String, T]){
    for((elementKey, element) <- elements){
      validate(element)
    }
  }
  
  private def validate(element : Any){
    element match {
      case process : ProcessConfig => {
        validate(process)
      }
      case rule : RuleConfig => {
        validate(rule)
      }
      case flow : FlowConfig => {
        validate(flow)
      }
      case _ => {
        throw new RequestUnsupportedException(element)
      }
    }
  }
  
  
  
  
  private def validate(rule : RuleConfig){
    
  }
  
  private def validate(flow : FlowConfig){
    if(flow == null) return;
   
  }
  
}